//
//  ContentView.swift
//  AnnCardApp
//
//  Created by Developer on 2024/06/15.
//

import SwiftUI

struct ContentView: View {
    @StateObject private var viewModel = CardViewModel()
    
    var body: some View {
        NavigationView {
            VStack(spacing: 20) {
                // 应用标题
                Text("Ann Card App")
                    .font(.largeTitle)
                    .fontWeight(.bold)
                    .foregroundColor(.primary)
                
                // 卡片显示区域
                if let currentCard = viewModel.currentCard {
                    CardView(card: currentCard)
                        .padding()
                } else {
                    Text("没有可用的卡片")
                        .font(.title2)
                        .foregroundColor(.secondary)
                        .padding()
                }
                
                // 控制按钮
                HStack(spacing: 30) {
                    Button(action: {
                        viewModel.previousCard()
                    }) {
                        Image(systemName: "chevron.left.circle.fill")
                            .font(.title)
                            .foregroundColor(.blue)
                    }
                    .disabled(!viewModel.hasPreviousCard)
                    
                    Button(action: {
                        viewModel.shuffleCards()
                    }) {
                        Image(systemName: "shuffle.circle.fill")
                            .font(.title)
                            .foregroundColor(.green)
                    }
                    
                    Button(action: {
                        viewModel.nextCard()
                    }) {
                        Image(systemName: "chevron.right.circle.fill")
                            .font(.title)
                            .foregroundColor(.blue)
                    }
                    .disabled(!viewModel.hasNextCard)
                }
                .padding()
                
                // 进度指示器
                if viewModel.totalCards > 0 {
                    Text("\(viewModel.currentIndex + 1) / \(viewModel.totalCards)")
                        .font(.caption)
                        .foregroundColor(.secondary)
                }
                
                Spacer()
            }
            .padding()
            .navigationBarHidden(true)
        }
        .onAppear {
            viewModel.loadSampleCards()
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
